<?php
Cinnamon::loadClass('Event');

/**
 * Default Track Event
 */
class TrackEvent extends Event {
	protected $parameters;
	
	/**
	 * Default constructor
	 */
	public function __construct() {
		parent::__construct('track');
		
		$this->parameters = array();
		
		for ( $i=0; $i<func_num_args(); $i+=2 ) {
			$this->{func_get_arg($i)} = func_get_arg(($i+1));
		}	
	}
	
	/**
	 * Adds a visit parameter to be stored in visits table. It can be: a string, a number, an object or array. Use the third parameter to specify if this parameter has been escaped (is an optional parameter - the default value is false). If it hasn't, it will be escaped. Please note that the numeric strings will not be considered as numbers!
	 *
	 * @param string name the parameter name
	 * @param string value the parameter value
	 * @param boolean escaped indicates if the parameter value has been escaped (optional parameter - the default value is false)
	 */
	public function addParameter($name, $value, $escaped=false) {
		if ( !$escaped ) {
			$value = Cinnamon::registry('db')->escape($value);
		}
		$this->parameters[$name] = $value;
	}
	
	/**
	 * Adds an escaped visits parameter to be stored in visits table. It can be an escaped value of: a string, a number, an object or an array. Please note that the numeric string will not be considered as numbers!
	 * @param string name the parameter name
	 * @param string value the parameter value
	 */
	public function addEscapedParameter($name, $value) {
		$this->addParameter($name, $value, true);
	}
	
	/**
	 * Returns all the parameters, in array
	 */
	public function getAllParameters() {
		return $this->parameters;
	}
}
?>